package wps

import (
	"github.com/zzl/go-com/com"
	"github.com/zzl/go-com/ole"
	"github.com/zzl/go-win32api/v2/win32"
	"syscall"
	"unsafe"
)

// 000244CE-0000-0000-C000-000000000046
var IID_TableObject = syscall.GUID{0x000244CE, 0x0000, 0x0000,
	[8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}

type TableObject struct {
	ole.OleClient
}

func NewTableObject(pDisp *win32.IDispatch, addRef bool, scoped bool) *TableObject {
	if pDisp == nil {
		return nil
	}
	p := &TableObject{ole.OleClient{pDisp}}
	if addRef {
		pDisp.AddRef()
	}
	if scoped {
		com.AddToScope(p)
	}
	return p
}

func TableObjectFromVar(v ole.Variant) *TableObject {
	return NewTableObject(v.IDispatch(), false, false)
}

func (this *TableObject) IID() *syscall.GUID {
	return &IID_TableObject
}

func (this *TableObject) GetIDispatch(addRef bool) *win32.IDispatch {
	if addRef {
		this.AddRef()
	}
	return this.IDispatch
}

func (this *TableObject) QueryInterface_(riid *syscall.GUID, ppvObj unsafe.Pointer) {
	retVal, _ := this.Call(0x60000000, []interface{}{riid, ppvObj})
	_ = retVal
}

func (this *TableObject) AddRef() uint32 {
	retVal, _ := this.Call(0x60000001, nil)
	return retVal.UintValVal()
}

func (this *TableObject) Release() uint32 {
	retVal, _ := this.Call(0x60000002, nil)
	return retVal.UintValVal()
}

func (this *TableObject) GetTypeInfoCount(pctinfo *uint32) {
	retVal, _ := this.Call(0x60010000, []interface{}{pctinfo})
	_ = retVal
}

func (this *TableObject) GetTypeInfo(itinfo uint32, lcid uint32, pptinfo unsafe.Pointer) {
	retVal, _ := this.Call(0x60010001, []interface{}{itinfo, lcid, pptinfo})
	_ = retVal
}

func (this *TableObject) GetIDsOfNames(riid *syscall.GUID, rgszNames **int8, cNames uint32, lcid uint32, rgdispid *int32) {
	retVal, _ := this.Call(0x60010002, []interface{}{riid, rgszNames, cNames, lcid, rgdispid})
	_ = retVal
}

func (this *TableObject) Invoke(dispidMember int32, riid *syscall.GUID, lcid uint32, wFlags uint16, pdispparams *win32.DISPPARAMS, pvarResult *ole.Variant, pexcepinfo *win32.EXCEPINFO, puArgErr *uint32) {
	retVal, _ := this.Call(0x60010003, []interface{}{dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr})
	_ = retVal
}

func (this *TableObject) Application() *Application {
	retVal, _ := this.PropGet(0x00000094, nil)
	return NewApplication(retVal.IDispatch(), false, true)
}

func (this *TableObject) Creator() int32 {
	retVal, _ := this.PropGet(0x00000095, nil)
	return retVal.LValVal()
}

func (this *TableObject) Parent() *ole.DispatchClass {
	retVal, _ := this.PropGet(0x00000096, nil)
	return ole.NewDispatchClass(retVal.IDispatch(), true)
}

func (this *TableObject) RowNumbers() bool {
	retVal, _ := this.PropGet(0x00000631, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) SetRowNumbers(rhs bool) {
	_ = this.PropPut(0x00000631, []interface{}{rhs})
}

func (this *TableObject) FetchedRowOverflow() bool {
	retVal, _ := this.PropGet(0x00000634, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) RefreshStyle() int32 {
	retVal, _ := this.PropGet(0x00000636, nil)
	return retVal.LValVal()
}

func (this *TableObject) SetRefreshStyle(rhs int32) {
	_ = this.PropPut(0x00000636, []interface{}{rhs})
}

func (this *TableObject) EnableRefresh() bool {
	retVal, _ := this.PropGet(0x000005c5, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) SetEnableRefresh(rhs bool) {
	_ = this.PropPut(0x000005c5, []interface{}{rhs})
}

func (this *TableObject) Destination() *Range {
	retVal, _ := this.PropGet(0x000002a9, nil)
	return NewRange(retVal.IDispatch(), false, true)
}

func (this *TableObject) ResultRange() *Range {
	retVal, _ := this.PropGet(0x00000638, nil)
	return NewRange(retVal.IDispatch(), false, true)
}

func (this *TableObject) Delete() {
	retVal, _ := this.Call(0x00000075, nil)
	_ = retVal
}

func (this *TableObject) Refresh() bool {
	retVal, _ := this.Call(0x00000589, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) EnableEditing() bool {
	retVal, _ := this.PropGet(0x0000063b, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) SetEnableEditing(rhs bool) {
	_ = this.PropPut(0x0000063b, []interface{}{rhs})
}

func (this *TableObject) PreserveColumnInfo() bool {
	retVal, _ := this.PropGet(0x0000074b, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) SetPreserveColumnInfo(rhs bool) {
	_ = this.PropPut(0x0000074b, []interface{}{rhs})
}

func (this *TableObject) PreserveFormatting() bool {
	retVal, _ := this.PropGet(0x000005dc, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) SetPreserveFormatting(rhs bool) {
	_ = this.PropPut(0x000005dc, []interface{}{rhs})
}

func (this *TableObject) AdjustColumnWidth() bool {
	retVal, _ := this.PropGet(0x0000074c, nil)
	return retVal.BoolValVal() != win32.VARIANT_FALSE
}

func (this *TableObject) SetAdjustColumnWidth(rhs bool) {
	_ = this.PropPut(0x0000074c, []interface{}{rhs})
}

func (this *TableObject) ListObject() *ListObject {
	retVal, _ := this.PropGet(0x000008d1, nil)
	return NewListObject(retVal.IDispatch(), false, true)
}

func (this *TableObject) WorkbookConnection() *WorkbookConnection {
	retVal, _ := this.PropGet(0x000009f0, nil)
	return NewWorkbookConnection(retVal.IDispatch(), false, true)
}
